package com.candy.databasedocuments.service;

import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Map;

/**
 * @author suYanLong
 * @version 1.0
 * @date 2023/7/5 15:44
 * @Description 数据库链接工厂
 */
@Component
public class DatabaseConnectFactory {

    private static Map<String, DatabaseConnect> map;

    public DatabaseConnectFactory(Map<String, DatabaseConnect> map) {
        this.map = map;
    }

    public static DatabaseConnect getDatabaseConnect(String type) {
        if (CollectionUtils.isEmpty(map) || !map.containsKey(type)) {
            throw new RuntimeException("不支持此类型");
        }
        return map.get(type);
    }

}
